#ifndef UTILITIES_H
#define UTILITIES_H

#include "basicheader.h"

#define _UTILITIES_BEGIN_ namespace utilities {
#define _UTILITIES_END_	};

using namespace std;	// test
using std::string;
using std::vector;

_UTILITIES_BEGIN_

/************************************************************************/
/*	Split the line into tokens by using the given delim.                */
/*	Parameters:															*/
/*		line - the input line											*/
/*		delim - the delim that split the line, default ' '				*/
/*	Return:																*/
/*		a set of the splitted tokens									*/
/************************************************************************/
vector<string> Split(const string& line, char delim = ' ');

/************************************************************************/
/*	Calculate the distance of two points.                               */
/*	Parameters:															*/
/*		x0 - the x coordinate of the first point						*/
/*		y0 - the y coordinate of the first point						*/
/*		y1 - the x coordinate of the second point						*/
/*		y2 - the y coordinate of the second point						*/
/*	Return:																*/
/*		the value of the distance.										*/
/************************************************************************/
double calculateEuclideanDistance(double x0, double y0, double x1, double y1);

/************************************************************************/
/*	Calculate the parameters of the line by the two given points.		*/
/*	y=kx+b, return the pair of k(first) and b(second).                  */
/*	Parameters:															*/
/*		x0 - the x coordinate of the first point						*/
/*		y0 - the y coordinate of the first point						*/
/*		y1 - the x coordinate of the second point						*/
/*		y2 - the y coordinate of the second point						*/
/*	Return:																*/
/*		the value of the parameters in the form of pair, the first		*/
/*		value is k and the second is b.									*/
/************************************************************************/
std::pair<double, double> calculateLineParameters(double x0, double y0, double x1, double y1);

/************************************************************************/
/*	Calculate the l-perpendicular value between a point of a partition	*/
/*	to another partition.												*/
/*	Parameters:															*/
/*		x0			- the x coordinate of the point						*/
/*		y0			- the y coordinate of the point						*/
/*		lineParam	- the parameters of Lj								*/
/*	Return:																*/
/*		the value of the L-perpendicular, that is the distance from the */
/*		point to the line with the parameter linePara					*/
/************************************************************************/
double calculateLperpendicular(double x0, double y0, std::pair<double, double> linePara);

/************************************************************************/
/*	Calculate the d-perpendicular value between two partitions.			*/
/*	From L1 to L2, lp1 and lp2 are the distances from two points of L1  */
/*	to L2.																*/
/*	Parameters:															*/
/*		lp1 - the value of l-perpendiculer from the first point			*/
/*		lp2 - the value of l-perpendicular from the second point		*/
/*	Return:																*/
/*		the value of d-perpendicular									*/
/************************************************************************/
double calculatePerpendicularDistance(double lp1, double lp2);
double calculatePerpendicularDistanceEx(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3);

/************************************************************************/
/*	Calculate the D-theta value from Li to Lj.		                    */
/*	Parameters:															*/
/*		x0 - the x coordinate of the first point of Lj					*/
/*		y0 - the y coordinate of the first point of Lj					*/
/*		x1 - the x coordinate of the second point of Lj					*/
/*		y1 - the y coordinate of the second point of Lj					*/
/*		Li - the parameters of one line									*/
/*		Lj - the parameters of another line								*/
/*	Return:																*/
/*		the value of angle distance										*/
/************************************************************************/
double calculateAngleDistance(double x0, double y0, double x1, double y1, std::pair<double, double> Li, std::pair<double, double> Lj);
double calculateAngleDistanceEx(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3);

/************************************************************************/
/*	Calculate the D-parallel value between Li and Lj.                   */
/*	Parameters:															*/
/*		x0 - the x coordinate of the first point of Li					*/
/*		y0 - the y coordinate of the first point of Li					*/
/*		x1 - the x coordinate of the second point of Li					*/
/*		y1 - the y coordinate of the second point of Li					*/
/*		Lj - the parameters of Lj										*/
/*		x2 - the x coordinate of the first point of Lj					*/
/*		y2 - the y coordinate of the first point of Lj					*/
/*		x3 - the x coordinate of the second point of Lj					*/
/*		y3 - the y coordinate of the second point of Lj					*/
/*	Return:																*/
/*		the value of the parallel distance								*/
/************************************************************************/
double calculateParallelDistance(double x0, double y0, double x1, double y1, std::pair<double, double> Lj, double x2, double y2, double x3, double y3);
double calculateParallelDistanceEx(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3);

/************************************************************************/
/*	Calculate the Distance between two partition.                       */
/*	Parameters:															*/
/*		x0		- the x coordinate of the first point of Li				*/
/*		y0		- the y coordinate of the first point of Li				*/
/*		x1		- the x coordinate of the second point of Li			*/
/*		y1		- the y coordinate of the second point of Li			*/
/*		x2		- the x coordinate of the first point of Lj				*/
/*		y2		- the y coordinate of the first point of Lj				*/
/*		x3		- the x coordinate of the second point of Lj			*/
/*		y3		- the y coordinate of the second point of Lj			*/
/*		Wper	- the weight for the perpendicular distance				*/
/*		Wpar	- the weight for the parallel distance					*/
/*		Wthe	- the weight for the theta distance						*/
/*	Return:																*/
/*		the value of the distance										*/
/************************************************************************/
double calculateDistance(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double Wper, double Wpar, double Wthe);


_UTILITIES_END_

#endif